def calculate_y1(x1, x2, x3):
    y_i = 0.496 * x1 + 0.567 * x2 - 100.046 * x3 + 5.499 * x3**2 - 0.090 * x3**3 + 1644.941
    return y_i
def calculate_y2(x1, x2, x3):
    y_i = -0.285 * x1 + 0.053 * x2 - 3.721 * x3 + 0.224 * x3**2 - 0.004 * x3**3 + 105.786
    return y_i
def calculate_y3(x1, x2, x3):
    y_i = -4.320 * x1 + 0.362 * x2 - 10.379 * x3 - 0.101 * x1 * x3 + 0.047 * x1**2 + 0.395 * x3**2 - 0.001 * x3**3 + 189.837
    return y_i
def calculate_y4(x1, x2, x3):
    y_i = 22.863 * x1 - 1.597 * x2 + 32.268 * x3 - 0.172 * x1 * x3 - 0.401 * x1**2 - 2.368 * x3**2 + 0.044 * x3**3 + 73.167
    return y_i
def calculate_y5(x1, x2, x3):
    y_i = -1214.089 * x1 - 182.990 * x2 - 69.051 * x3 + 0.494 * x1 * x2 + 2.878 * x1 * x3 + 0.494 * x2 * x3 + 42.671 * x1**2 - 0.585 * x3**3 + 0.723 * x2**2 + 0.363 * x3**2 + 23669.459
    return y_i
def calculate_y6(x1, x2, x3):
    y_i = -0.048 * x1 + 0.006 * x2 + 0.068 * x3 + 1.442
    return y_i
def calculate_y7(x1, x2, x3):
    y_i = -0.012 * x1 + 0.108 * x2 + 0.493 * x3 + 140.43
    return y_i
def Optimal_mechanical_properties(m1, m2, m3):
    return (m1-1331.605625)/233.5740652+(m2-94.32432083)/8.161031342+(m3-117.27)/26.17596577

def Hot_wet_comfort_performance(m4, m5):
    return (m4-183.5229167)/73.27417756+(m5-2626.767 )/402.387

def Soft_performance(m6, m7):
    return (m6-2.07)/0.84 +(m7-160.03 )/6.63


def Optimal_Hot_wet_comfort_performance(h1,h2,h3):
    return h1+h2+h3;

import optuna


def objective_y1_y2_y3(trial):
    # 2. 使用trial对象建议超参数取值
    x1 = trial.suggest_categorical('x1', [15, 20, 25, 30])
    x2 = trial.suggest_categorical('x2', [100, 110, 120, 130])
    x3 = trial.suggest_categorical('x3', [0, 10, 20, 30])
    return Optimal_mechanical_properties(calculate_y1(x1,x2,x3),calculate_y2(x1,x2,x3),calculate_y3(x1,x2,x3))


def objective_y4_y5(trial):
    # 2. 使用trial对象建议超参数取值
    x1 = trial.suggest_categorical('x1', [15, 20, 25, 30])
    x2 = trial.suggest_categorical('x2', [100, 110, 120, 130])
    x3 = trial.suggest_categorical('x3', [0, 10, 20, 30])
    return Hot_wet_comfort_performance(calculate_y4(x1,x2,x3),calculate_y5(x1,x2,x3))


def objective_y6_y7(trial):
    # 2. 使用trial对象建议超参数取值
    x1 = trial.suggest_categorical('x1', [15, 20, 25, 30])
    x2 = trial.suggest_categorical('x2', [100, 110, 120, 130])
    x3 = trial.suggest_categorical('x3', [0, 10, 20, 30])
    return Soft_performance(calculate_y6(x1,x2,x3),calculate_y7(x1,x2,x3))

def objective_y1_y7(trial):
    # 2. 使用trial对象建议超参数取值
    x1 = trial.suggest_categorical('x1', [15, 20, 25, 30])
    x2 = trial.suggest_categorical('x2', [100, 110, 120, 130])
    x3 = trial.suggest_categorical('x3', [0, 10, 20, 30])
    h1=Optimal_mechanical_properties(calculate_y1(x1, x2, x3), calculate_y2(x1, x2, x3), calculate_y3(x1, x2, x3))
    h2=Hot_wet_comfort_performance(calculate_y4(x1,x2,x3),calculate_y5(x1,x2,x3))
    h3=Soft_performance(calculate_y6(x1,x2,x3),calculate_y7(x1,x2,x3))
    return Optimal_Hot_wet_comfort_performance(h1,h2,h3)

study = optuna.create_study(direction='maximize')

 # 运行Optuna搜索
study.optimize(objective_y1_y2_y3, n_trials=100)

# 打印最佳超参数和得分
print('Best hyperparameters: ', study.best_params)

print('Best score: ', study.best_value)
